﻿using System;
using System.Collections.Generic;
using System.Text;
using System.Windows.Forms;

namespace TerrainViewer
{
    /// <summary>
    /// Customized combo box with disabled mouse wheel
    /// </summary>
    public class NoWheelComboBox : ComboBox
    {
        private int _selectedIndex = 0;
        private bool _onMouseWheel = false;

        protected override void OnMouseWheel(MouseEventArgs e)
        {
            _onMouseWheel = true;
            _selectedIndex = this.SelectedIndex;
            MouseEventArgs eMouse = new MouseEventArgs(e.Button, e.Clicks, e.X, e.Y, 0);
            base.OnMouseWheel(eMouse);
        }

        protected override void OnSelectedIndexChanged(EventArgs e)
        {
            if (_onMouseWheel)
            {
                if (SelectedIndex != _selectedIndex) SelectedIndex = _selectedIndex;
                _onMouseWheel = false;
            }
            base.OnSelectedIndexChanged(e);
        }

    //Protected Overloads Overrides Sub OnMouseWheel(ByVal e As MouseEventArgs)
    //    _onMouseWheel = True
    //    _selectedIndex = Me.SelectedIndex
    //    Dim eMouse As New MouseEventArgs(e.Button, e.Clicks, e.X, e.Y, 0)
    //    MyBase.OnMouseWheel(eMouse)
    //End Sub
    //Protected Overloads Overrides Sub OnSelectedIndexChanged(ByVal e As EventArgs)
    //    If _onMouseWheel Then
    //        If Me.SelectedIndex <> _selectedIndex Then Me.SelectedIndex = _selectedIndex
    //        _onMouseWheel = False
    //    End If
    //    MyBase.OnSelectedIndexChanged(e)
    //End Sub

    }
}
